import {createApp} from 'vue'
import App from './App.vue'
import * as VueRouter from 'vue-router'
import {routers} from '@/config/routers'
import axios from 'axios'
import VueAxios from 'vue-axios'
import NutUI from "@nutui/nutui";
import {Notify} from '@nutui/nutui';
import "@nutui/nutui/dist/style.css";

const router = VueRouter.createRouter({
    history: VueRouter.createWebHashHistory(),
    routes: routers,
})

const service = axios.create({
    baseURL: process.env.NODE_ENV === 'production' ? '/web' : '/web',
    timeout: 9000
})
service.interceptors.response.use(response => {
    // response.data.token && localStorage.setItem("token", response.data.token);
    return response.data
})
service.interceptors.request.use(request => {
    // const token = localStorage.getItem('token');
    // token && (request.headers['X-CSRFToken'] = token);
    let tokens = document.cookie.split(';').map(cookie => cookie.split('=')).filter(c => c.length == 2 && c[0] == 'csrftoken')
    if (tokens.length > 0) {
        request.headers['X-CSRFToken'] = tokens[0][1]
    }
    return request
})

createApp(App).use(router).use(VueAxios, service).use(NutUI).use(Notify).mount("#app");
